package crud.client.data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import com.google.gwt.user.client.rpc.IsSerializable;

import crud.client.data.authentication.Right;
import crud.client.dialog.factory.TableCRUDFactory;
import crud.client.dialog.factory.WindowFactory;
import crud.client.factory.validator.table.TableValidatorFactory;

public class Table implements Serializable, IsSerializable
{
	private String libelle;
	private String mappingClassName;
	private WindowFactory windowFactory;
	private String windowFactoryClassName = TableCRUDFactory.class.getName();
	private List<DependenceToOne> dependingEntities = new ArrayList<DependenceToOne>();
	private Right right;


	public String getMappingClassName()
	{
		return mappingClassName;
	}

	public void setMappingClassName(String mappingClassName)
	{
		this.mappingClassName = mappingClassName;
	}

	public String getLibelle()
	{
		return libelle;
	}

	public void setLibelle(String libelle)
	{
		this.libelle = libelle;
	}

	public void setWindowFactoryClassName(String windowFactoryClassName)
	{
		this.windowFactoryClassName = windowFactoryClassName;
	}

	public String getWindowFactoryClassName()
	{
		return windowFactoryClassName;
	}

	public void setWindowFactory(WindowFactory windowFactory)
	{
		this.windowFactory = windowFactory;
	}

	public WindowFactory getWindowFactory()
	{
		return windowFactory;
	}

	public List<DependenceToOne> getDependingEntities()
	{
		return dependingEntities;
	}

	public void setDependingEntities(List<DependenceToOne> dependingEntities)
	{
		this.dependingEntities = dependingEntities;
	}

	public boolean depends(String dependsClassNameToCheck)
	{
		for (DependenceToOne dependingEntity : dependingEntities)
		{
			if (dependsClassNameToCheck.equals(dependingEntity.getDependentClassName()))
			{
				return true;
			}
		}
		
		return false;
	}
	
	@Override
	public int hashCode()
	{
		return mappingClassName.hashCode();
	}
	
	@Override
	public boolean equals(Object table)
	{
		return mappingClassName.equals(((Table)table).getMappingClassName());
	}

	public Right getRight()
	{
		return right;
	}

	public void setRight(Right right)
	{
		this.right = right;
	}

	
}
